<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Le8
 *
 * @author dragon.hu add @2016.3.2
 */
require_once 'BaseChannel.php';

//乐8
class Le8 implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey=""; //
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey="c427367e096c7f66b62f10d1c7b6b360"; //appkey
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("le8", $_REQUEST);
		
		$n_time = $_REQUEST['n_time'];
		$appid = $_REQUEST['appid'];
		$o_id = $_REQUEST['o_id'];
		$t_fee = $_REQUEST['t_fee'];
		$g_name = $_REQUEST['g_name'];
		$g_body = $_REQUEST['g_body'];
		$t_status = $_REQUEST['t_status'];
		$o_sign = $_REQUEST['o_sign'];
		$u_param = $_REQUEST['u_param'];
		$o_orderid = $_REQUEST['o_orderid'];
		
		$mysign = "n_time=".urlencode($n_time)."&appid=".urlencode($appid)."&o_id=".urlencode($o_id)."&t_fee=".urlencode($t_fee)."&g_name=".urlencode($g_name).
		"&g_body=".urlencode($g_body)."&t_status=".urlencode($t_status).$paymentKey;
		
		if($o_sign == md5($mysign))  
		{ //验证通过
			 $tmpstatus = STATUS_SUCCESS;
			 if ($t_status != 1)
			 {
			 	$tmpstatus = STATUS_FAILD;
			 }
			//进行发货
			if(false == $orderLog->recordOrder($tmpstatus, $t_fee, $o_id, "IosLeBa", $platform,$o_orderid))
			{
				$ret="failure";
				$orderLog->log("le8",array("order"=>$o_id,"money"=>$t_fee,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="success";
				$orderLog->log("le8",array("order"=>$o_id,"money"=>$t_fee,"serverresult"=>"success"));
			}
			 
		} else {
			//"$sig验证失败"
			$ret="failure";
			$orderLog->log("le8","  order:$o_id  sign error sign:$o_sign mysign:$mysign");
		}
		return $ret;
	}
	
}